﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Radius.NET.Interface.Kingdee.Entity
{
    /// <summary>
    /// 直接调拨单
    /// </summary>
    public class STK_TransferDirect : KingdeePubClass
    {
        /// <summary>
        /// 实体
        /// </summary>
        public STK_TransferDirect_Model? Model { get; set; }

        #region 直接调拨单表头
        /// <summary>
        /// 直接调拨单表头
        /// </summary>
        public class STK_TransferDirect_Model
        {
            /// <summary>
            /// 
            /// </summary>
            public int FID { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FBillNo { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FBillTypeID? FBillTypeID { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public string? FBizType { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public string? FTransferDirect { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FTransferBizType { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FSettleOrgId? FSettleOrgId { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FSaleOrgId? FSaleOrgId { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FStockOutOrgId? FStockOutOrgId { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public string? FOwnerTypeOutIdHead { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FOwnerOutIdHead? FOwnerOutIdHead { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FStockOrgId? FStockOrgId { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public bool? FIsIncludedTax { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public bool? FIsPriceExcludeTax { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FExchangeTypeId? FExchangeTypeId { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public string? FOwnerTypeIdHead { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FSETTLECURRID? FSETTLECURRID { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public double? FExchangeRate { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FOwnerIdHead? FOwnerIdHead { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public string? FDate { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public string? FNote { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FBaseCurrId? FBaseCurrId { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FSUPPLIERID? FSUPPLIERID { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public FCustID? FCustID { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public string? F_asdg_Combo { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public F_asdg_Base? F_asdg_Base { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public List<FBillEntry>? FBillEntry { set; get; } = new List<FBillEntry>();
        } 
        #endregion

        #region 直接调拨明细
        /// <summary>
        /// 直接调拨明细
        /// </summary>
        public class FBillEntry
        {
            /// <summary>
            /// 
            /// </summary>
            public int FEntryID { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FMaterialId? FMaterialId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FAuxPropId? FAuxPropId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FUnitID? FUnitID { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FLot? FLot { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FSrcStockId? FSrcStockId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FSrcStockLocId? FSrcStockLocId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FDestStockId? FDestStockId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FDestStockLocId? FDestStockLocId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FBomId? FBomId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FSrcStockStatusId? FSrcStockStatusId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FDeliChkQualifyType { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FProduceDate { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FDestStockStatusId? FDestStockStatusId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FMtoNo { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FBusinessDate { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FExpiryDate { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FOwnerTypeOutId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FOwnerOutId? FOwnerOutId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FOwnerTypeId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FOwnerId? FOwnerId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FNoteEntry { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FProjectNo { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FSecUnitId? FSecUnitId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FSecQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FExtAuxUnitId? FExtAuxUnitId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FExtAuxUnitQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FBaseUnitId? FBaseUnitId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FBaseQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public bool? FISFREE { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FKeeperTypeId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FActQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FKeeperId? FKeeperId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FKeeperTypeOutId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FKeeperOutId? FKeeperOutId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FDiscountRate { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FRepairQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FRETURNNOTE { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FDestLot? FDestLot { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FDestMaterialId? FDestMaterialId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FDestBomId? FDestBomId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FSaleUnitId? FSaleUnitId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FSaleQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FSalBaseQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public FPriceUnitID? FPriceUnitID { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FPriceQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? FPriceBaseQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FOutJoinQty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FBASEOUTJOINQTY { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FServiceContext { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FSOEntryId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public bool? FTransReserveLink { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FQmEntryId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int? FConvertEntryId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string? FThirdSrcEntryId { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public bool? FCheckDelivery { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public bool? FStockOutFlag { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public bool? FStockInFlag { set; get; }
            /// <summary>
            /// 
            /// </summary>
            public F_asdg_Base? F_asdg_Base { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public double? F_asdg_Qty { get; set; }
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        public class F_asdg_Base
        {
            /// <summary>
            /// 编码
            /// </summary>
            public string FNumber { set; get; } = string.Empty;
        }
        /// <summary>
        /// 
        /// </summary>
        public class FAuxPropId
        {
            /// <summary>
            /// 
            /// </summary>
            public class FAUXPROPID__FF100002_Model
            {
                /// <summary>
                /// 
                /// </summary>
                public string FNumber { set; get; } = string.Empty;
            }
            /// <summary>
            /// 
            /// </summary>
            public FAUXPROPID__FF100002_Model? FAUXPROPID__FF100002 { set; get; }
        }

        #region 生成直接调拨单表单数据
        /// <summary>
        /// 生成直接调拨单表单数据
        /// </summary>
        /// <param name="item"></param>
        /// <param name="materials"></param>
        /// <returns></returns>
        public object BuildData(InventoryEvidence item, Dictionary<string, BD_MATERIAL_Dto> materials)
        {
            var obj = new STK_TransferDirect()
            {
                Model = new STK_TransferDirect_Model()
                {
                    FID = 0,
                    FBillNo = item.Evidence_Number,
                    FBillTypeID = new FBillTypeID()
                    {
                        FNumber = "ZJDB01_SYS"
                    },
                    FBizType = "NORMAL",
                    FTransferDirect = "GENERAL",
                    FTransferBizType = "InnerOrgTransfer",
                    FSettleOrgId = new FSettleOrgId
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FSaleOrgId = new()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FStockOutOrgId = new FStockOutOrgId()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FOwnerTypeOutIdHead = "BD_OwnerOrg",
                    FOwnerOutIdHead = new FOwnerOutIdHead()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FStockOrgId = new()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FIsIncludedTax = true,
                    FIsPriceExcludeTax = true,
                    FExchangeTypeId = new FExchangeTypeId()
                    {
                        FNumber = "HLTX01_SYS"
                    },
                    FOwnerTypeIdHead = "BD_OwnerOrg",
                    FSETTLECURRID = new FSETTLECURRID()
                    {
                        FNumber = "PRE001"
                    },
                    FExchangeRate = 1.0,
                    FOwnerIdHead = new()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FDate = item.Date?.ToString("yyyy-MM-dd HH:mm:ss"),
                    FNote = item.Remark == null ? "" : item.Remark,
                    FBaseCurrId = new()
                    {
                        FNumber = "PRE001"
                    },
                    FSUPPLIERID = new FSUPPLIERID()
                    {
                        FNumber = ""
                    },
                    FCustID = new FCustID()
                    {
                        FNumber = ""
                    },
                    F_asdg_Combo = "NJ",
                    F_asdg_Base = new()
                    {
                        FNumber = item.DesStock_ID
                    },
                    FBillEntry = new List<FBillEntry>(),
                }
            };

            foreach (var child in item.FG_InvDetail)
            {
                obj.Model.FBillEntry.Add(new()
                {
                    FMaterialId = new()
                    {
                        FNumber = child.Inventory_ID
                    },
                    FAuxPropId = new()
                    {
                        FAUXPROPID__FF100002 = new()
                        {
                            FNumber = child.PackID
                        }
                    },
                    FUnitID = new()
                    {
                        FNumber = child.FG_Inventory.Unit
                    },
                    FQty = child.Actual_Qty,
                    FSecUnitId = new()
                    {
                        FNumber = materials.ContainsKey(child.Inventory_ID) ? materials[child.Inventory_ID].FAuxUnitID__FNumber : "Tong"
                    },
                    FSecQty = child.Actual_Qty / child.Unit_weight,
                    FLot = new()
                    {
                        FNumber = child.ProjectBatch
                    },
                    FSrcStockId = new FSrcStockId()
                    {
                        FNumber = child.Inventory_ID.EndsWith("HG") ? "BJ04" : item.Stock_ID
                    },
                    FDestStockId = new FDestStockId()
                    {
                        FNumber = item.DesStock_ID
                    },
                    FProduceDate = child.MakeBeginDate?.ToString("yyyy-MM-dd HH:mm:ss"),
                    FExpiryDate = child.EndDate?.ToString("yyyy-MM-dd HH:mm:ss"),
                    F_asdg_Qty = child.Actual_Qty,
                    FSrcStockStatusId = new FSrcStockStatusId()
                    {
                        FNumber = "KCZT01_SYS"
                    },
                    FDestStockStatusId = new FDestStockStatusId()
                    {
                        FNumber = "KCZT01_SYS"
                    },
                    FBusinessDate = item.Date?.ToString("yyyy-MM-dd HH:mm:ss"),
                    FOwnerTypeOutId = "BD_OwnerOrg",
                    FOwnerOutId = new FOwnerOutId()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FOwnerTypeId = "BD_OwnerOrg",
                    FOwnerId = new()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FExtAuxUnitId = new()
                    {
                        FNumber = materials.ContainsKey(child.Inventory_ID) ? materials[child.Inventory_ID].FAuxUnitID__FNumber : "Tong"
                    },
                    FExtAuxUnitQty = child.Actual_Qty / child.Unit_weight,
                    FBaseUnitId = new()
                    {
                        FNumber = child.FG_Inventory.Unit
                    },
                    FBaseQty = child.Actual_Qty,
                    FISFREE = false,
                    FKeeperTypeId = "BD_KeeperOrg",
                    FKeeperId = new()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FKeeperTypeOutId = "BD_KeeperOrg",
                    FKeeperOutId = new FKeeperOutId()
                    {
                        FNumber = KingdeeConfigConst.ORGID
                    },
                    FDestLot = new FDestLot()
                    {
                        FNumber = child.ProjectBatch
                    },
                    FDestMaterialId = new FDestMaterialId()
                    {
                        FNumber = child.Inventory_ID
                    },
                    FSaleUnitId = new FSaleUnitId()
                    {
                        FNumber = child.FG_Inventory.Unit
                    },
                    FSaleQty = child.Actual_Qty,
                    FSalBaseQty = child.Actual_Qty,
                    FPriceUnitID = new FPriceUnitID()
                    {
                        FNumber = child.FG_Inventory.Unit
                    },
                    FPriceQty = child.Actual_Qty,
                    FPriceBaseQty = child.Actual_Qty,
                    FCheckDelivery = false,
                    FTransReserveLink = false
                });
            }
            return obj;
        }
    } 
    #endregion
}
